//import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import '../../common/custom_icons.dart';
import '../../utils/tools/screenutil_tool.dart';
import './concreteicon_widget.dart';

class ToastWidget {

//  static EasyLoading _loading = null;
//
//  ToastWidget(){
//    _loading = EasyLoading.instance;
//    _loading.indicatorType = EasyLoadingIndicatorType.circle;
//  }


//  static ToastWidget _single = ToastWidget._init();
//
//  static ToastWidget get instance => _getInstance();
//
//  static ToastWidget _getInstance(){
//    return _single;
//  }
//
//  ToastWidget._init() {
//    EasyLoading.instance
//      ..indicatorType = EasyLoadingIndicatorType.circle;
//  }

  /// ### 轻提示
  /// #### [context] 上下文
  /// #### [title] String|必填|提示文案
  static toast(String title, {int delayed = 2,
    EasyLoadingToastPosition position = EasyLoadingToastPosition.center}) {
    _changeEasyConfig(true);
    EasyLoading.showToast(title, toastPosition:position);
  }



  /// ### 结果提示
  /// #### [type] bool|选填|弹窗类型|默认：true，成功状态
  /// #### [title] String|选填|提示文案|默认值：请求成功
  /// #### [delayed] int|选填|延时关闭的时间|单位/秒
  static result({ bool type = true, String title = "请求成功", int delayed = 3 }){
    _changeEasyConfig(false);
    if(type) {
      EasyLoading.showSuccess(title,duration: Duration(seconds: delayed));
    } else {
      EasyLoading.showError(title,duration: Duration(seconds: delayed));
    }
  }


  /// ### 加载动画
  /// #### [title] String|选填|提示文案|默认值：正在加载...
  static loading({ String title = "正在加载..." }) {
    _changeEasyConfig(false);
    EasyLoading.show(status: title);
  }


  /// ### 关闭所有BotToast弹出
  static closeToast() => EasyLoading.dismiss();

  /// ### 修改Easy默认配置
  /// #### [flag] bool|必填|标记是否需要调整内边距
  static void _changeEasyConfig(bool flag) {
    if(flag){
      EasyLoading.instance
        ..contentPadding = EdgeInsets.symmetric(vertical: 5,horizontal: 15);
    } else {
      EasyLoading.instance
        ..contentPadding = EdgeInsets.symmetric(vertical: 15,horizontal: 20);
    }
  }

}

//class ToastWidget {
//
//  ToastWidget() {
//    EasyLoading.instance
//      ..indicatorType = EasyLoadingIndicatorType.circle;
//  }
//
//  /// ### 轻提示
//  /// #### [context] 上下文
//  /// #### [title] String|必填|提示文案
//  /// #### [delayed] int|选填|延时关闭|默认值：2s
//  static toast(BuildContext context, String title, {int delayed = 2}) {
//    final size = MediaQuery.of(context).size;
//    return BotToast.showAttachedWidget(
//        attachedBuilder: (_) => Container(
//          padding: EdgeInsets.symmetric(
//            vertical: ST.setw(20),
//            horizontal: ST.seth(20)
//          ),
//          decoration: BoxDecoration(
//            color: Colors.black,
//            borderRadius: BorderRadius.all(Radius.circular(5))
//          ),
//          child: Text(title,
//            style: TextStyle(
//              color: Colors.white
//            )
//          ),
//        ),
//        duration: Duration(seconds: delayed),
//        target: Offset(size.width / 2, size.height / 2));
//  }
//
//
//  /// ### 结果提示
//  /// #### [type] bool|选填|弹窗类型|默认：true，成功状态
//  /// #### [title] String|选填|提示文案|默认值：请求成功
//  /// #### [delayed] int|选填|延时器|默认值：3s
//  static result({ bool type = true, String title = "请求成功", int delayed = 3 }){
//    /*
//      return BotToast.showCustomLoading(
//      toastBuilder: (_) => Center(
//        child: Container(
//          padding: EdgeInsets.symmetric(vertical: ST.setw(25),horizontal: ST.seth(40)),
//          decoration: BoxDecoration(
//            color: Colors.black,
//            borderRadius: BorderRadius.all(Radius.circular(5))
//          ),
//          child: Column(
//            mainAxisSize: MainAxisSize.min,
//            mainAxisAlignment: MainAxisAlignment.center,
//            children: [
//              type ? Icon(CustomIcons.success, color: Colors.white,size: ST.setsp(100)):
//              Icon(Icons.error, color: Colors.white,size: ST.setsp(100)),
//              SizedBox(height: ST.seth(10)),
//              Text("$title",style: TextStyle(color: Colors.white,fontSize: ST.setsp(28)))
//            ],
//          ),
//        ),
//      ),
//      duration: Duration(seconds: delayed)
//    );
//    */
//    if(type) {
//      EasyLoading.showSuccess(title);
//    } else {
//      EasyLoading.showError(title);
//    }
//  }
//
//
//
//  /// 加载动画
//  /// * [title] String|选填|提示文案|默认值：正在加载...
//  static loading({ String title = "正在加载..." }) {
//    /*
//      return BotToast.showCustomLoading(toastBuilder: (_) =>
//        Center(
//          child: Container(
//            padding: EdgeInsets.symmetric(vertical: ST.setw(25),horizontal: ST.seth(35)),
//            decoration: BoxDecoration(
//                color: Colors.black,
//                borderRadius: BorderRadius.all(Radius.circular(5))
//            ),
//            child: Column(
//              mainAxisSize: MainAxisSize.min,
//              mainAxisAlignment: MainAxisAlignment.center,
//              children: [
//                Container(
//                  width: ST.setw(100),
//                  child: CW.circle(size: ST.setsp(90)),
//                ),
//                SizedBox(height: ST.seth(10)),
//                Text("$title",style: TextStyle(color: Colors.white,fontSize: ST.setsp(28)))
//              ],
//            ),
//          ),
//        )
//    );
//
//     */
//    return EasyLoading.show(status: title);
//  }
//
//  loadings({ String title = "正在加载..." }) {
//    /*
//      return BotToast.showCustomLoading(toastBuilder: (_) =>
//        Center(
//          child: Container(
//            padding: EdgeInsets.symmetric(vertical: ST.setw(25),horizontal: ST.seth(35)),
//            decoration: BoxDecoration(
//                color: Colors.black,
//                borderRadius: BorderRadius.all(Radius.circular(5))
//            ),
//            child: Column(
//              mainAxisSize: MainAxisSize.min,
//              mainAxisAlignment: MainAxisAlignment.center,
//              children: [
//                Container(
//                  width: ST.setw(100),
//                  child: CW.circle(size: ST.setsp(90)),
//                ),
//                SizedBox(height: ST.seth(10)),
//                Text("$title",style: TextStyle(color: Colors.white,fontSize: ST.setsp(28)))
//              ],
//            ),
//          ),
//        )
//    );
//
//     */
//    return EasyLoading.show(status: title);
//  }
//
//
//  /// * 关闭所有BotToast弹出
//  static closeBotToast() => EasyLoading.dismiss(); /*BotToast.cleanAll();*/
//
//  closeBotToasts() => EasyLoading.dismiss(); /*BotToast.cleanAll();*/
//
//}